import React, { Component } from 'react'
import { Form, Modal,  Input,Tabs } from 'antd'
const TabPane = Tabs.TabPane
const confirm = Modal.confirm;
import classnames from 'classnames/bind';
let cx = classnames.bind(styles);
const FormItem = Form.Item
import styles from './index.less'
// 引入列表页组件
import ListPage from 'widget/PageTmpl/ListPage'
const formItemLayout2 = {
    labelCol: { span: 4 },
    wrapperCol: { span: 16 },
};
export default class selectProjectModal extends Component {
    constructor(props) {
        super(props)
        this.state ={
            visible : this.props.visible || false,
            style : this.props.style || {},
            hrefModalObj:{},
            type:{
                'homeBanner':'横幅链接',
                'advertisingWindow':'广告链接',
                'codeChannel':'广告链接'
            }
        }    
    }
    componentDidMount(){
        this.setState({
            hrefModalObj:this.props.hrefModalObj
        })
    }
    componentWillReceiveProps(props){
        console.log(props)
        
    }
    changeTab_modal= (hrefType)=> {
        let {hrefModalObj, pageProps} = this.props
        hrefModalObj.hrefType = hrefType
        this.setState({
            pageProps:pageProps
        })
    }
    getHref= (params) =>{
        console.log(params,'params')//(1:推介 2：内部链接 3：资讯 4:外部链接 5：活动，6：预约看房，7：美房详情，10：自助购房，11：在线开盘，12：小游戏)
        let linkUrl = ''
        let obj = {
            0:'/pages/gameManage/gameTransferStation',
            1:'/pages/gameManage/game',
            2:'/pages/gameManage/game'
        }
        linkUrl = obj[params.gameType]||''
        let hrefMap = {
          1: {//推介
            hrefType: '1',
            linkUrl: [
                `/pages/recommend/recommend?productId=${params.productId}&mustRecommend=true`,
                `/pages/recommend/recommend?productId=${params.productId}&mustRecommend=true`,
                `pages/recommend/recommend?productId=${params.productId}&mustRecommend=true`,
            ],
            params: {productId: params.productId},
            btnName:params.name || params.btnName,
            query: 'productId',
          },
          2: {  //秒杀竞拍
            hrefType: '2',
            query: 'seckillActivityId',
            linkUrl: [
                `${params.type==1?'/pages/kill/killHome/killHome':'/pages/auctions/auction/auction'}?seckillActivityId=${params.seckillActivityId}`,
                `${params.type==1?'/pages/kill/killHome/killHome':'/pages/auctions/auction/auction'}?seckillActivityId=${params.seckillActivityId}`,
                `${params.type==1?'/pages/kill/killHome/killHome':'/pages/auctions/auction/auction'}?seckillActivityId=${params.seckillActivityId}`
            ],
            btnName:params.name || params.btnName,
            params: {seckillActivityId: params.seckillActivityId}
          },
          3: {  //资讯
            hrefType: '3',
            query: 'contentId',
            btnName:params.title,
            linkUrl: [
                `/pages/InformationDetail/InformationDetail?contentId=${params.contentId}`,
                `/pages/InformationDetail/InformationDetail?contentId=${params.contentId}`,
                `/subPackages/pages/InformationDetail/InformationDetail?contentId=${params.contentId}`
            ],
            params: {contentId: params.contentId}
          },
          4: {   //外部链接
            hrefType: '4',
            btnName:'',
            linkUrl: [`${params.linkUrl}`,`${params.linkUrl}`,`${params.linkUrl}`],
            params: {btnName: ''}
          },
          5: {   //活动
            hrefType: '5',
            query: 'contentId',
            btnName:params.title || params.btnName,
            // linkUrl: `/pages/findHouse/activity/apply/apply?contentId=${params.contentId}&productId=${params.productId}`,
            linkUrl: [
                `/pages/findHouse/activity/apply/apply?contentId=${params.contentId}`,
                `/pages/findHouse/activity/apply/apply?contentId=${params.contentId}`,
                `/pages/findHouse/activity/apply/apply?contentId=${params.contentId}`,
            ],
            params: {contentId: params.contentId}
          },
          6: {   //预约看房
            hrefType: '6',
            query: 'productId',
            btnName:params.name || params.btnName,
            // linkUrl: `/pages/findHouse/activity/apply/apply?contentId=${params.contentId}&productId=${params.productId}`,
            linkUrl: [
                `/pages/makeAppointment/makeAppointment?productId=${params.productId}&mustRecommend=true`,
                `/pages/makeAppointment/makeAppointment?productId=${params.productId}&mustRecommend=true`,
                `/subPackages/pages/makeAppointment/makeAppointment?productId=${params.productId}&mustRecommend=true`,
            ],
            params: {productId: params.productId}
          },
          7: {   //美房详情
            hrefType: '7',
            query: 'productId',
            btnName:params.name || params.btnName,
            // linkUrl: `/pages/findHouse/activity/apply/apply?contentId=${params.contentId}&productId=${params.productId}`,
            linkUrl: [
                `/pages/buildingDetail/buildingDetail?productId=${params.productId}`,
                `/pages/buildingDetail/buildingDetail?productId=${params.productId}`,
                `/subPackages/pages/buildingDetail/buildingDetail?productId=${params.productId}`
            ],
            params: {productId: params.productId}
          },
          
          8:{//不跳转
            hrefType: '8',
            btnName:params.name || params.btnName,
            linkUrl: ['','',''],
          },
          9: {  //优惠券
            hrefType: '9',
            linkUrl: [`${params.linkUrl}`,`${params.linkUrl}`,`/pages/couponsList/couponsList`],
            btnName:params.title || params.btnName,
            params: {contentId: params.contentId}
          },
          10: {   //自助购房
            hrefType: '10',
            query: 'activeId',
            btnName:params.activityName || params.btnName,
            linkUrl: [
                `/pages/HousingActivity/HousingKaiPanTransfer/HousingKaiPanTransfer?activeId=${params.id}`,
            ],
            params: {activeId: params.id}
          },
          11: {   //在线开盘
            hrefType: '11',
            query: 'activeId',
            btnName:params.activityName || params.btnName,
            linkUrl: [
                `/pages/HousingActivity/HousingKaiPanTransfer/HousingKaiPanTransfer?activeId=${params.id}`,
            ],
            params: {activeId: params.id}
          },
          12: {   //小游戏
            hrefType: '12',
            query: 'activeId',
            btnName:params.title || params.btnName,
            linkUrl: [
                `${linkUrl}?gameActivityId=${params.gameActivityId}`,
            ],
            params: {activeId: params.gameActivityId}
          },
          13: {   //直播
            hrefType: '13',
            query: 'activeId',
            btnName:params.title || params.btnName,
            linkUrl: [
                `/pages/liveRoom/wxcodeTransferStation/wxcodeTransferStation?liveBroadcastId=${params.id}`,
            ],
            params: {activeId: params.id}
          },
        }
        
        let item = hrefMap[params.hrefType+""] || {}
        console.log(item)
        return item
    }
     
    render() {
        let { visible,updateModal,pageProps,hrefModalObj,channelIndex,form,changeState,confirmHref,location=''} = this.props
        let { getFieldDecorator, validateFields } = form
        let {type} = this.state
        let self = this
        console.log(visible,updateModal,pageProps,'pageProps')
        return (
            <Modal
                visible={visible}
                onOk={()=>{
                    confirm({
                        title: '你是否确定编辑的内容？',
                        okText: '确定',
                        cancelText: '取消',
                        onOk() {
                            console.log(this,'this')
                            confirmHref(self.getHref)
                        },
                        onCancel() {
                        console.log('Cancel');
                        },
                    });
                }}
                onCancel={() => {
                    updateModal(false)
                }}
                width={'80%'}
            >
                <div style={{padding: '10px'}}>
                <div className={'mgb1'}>{type[this.props.type]}</div>
                    <Tabs onChange={this.changeTab_modal} type="line" activeKey={hrefModalObj.hrefType + ''||""}>
                        {location!='2'&&<TabPane tab=" 我要推介" key="1"></TabPane>}
                        {location!='2'&&<TabPane tab=" 预约看房" key="6"></TabPane>}
                        <TabPane tab=" 秒杀竞拍" key="2"></TabPane>
                        {channelIndex==1&&
                            <TabPane tab=" 资讯" key="3"></TabPane>
                            }
                        {channelIndex==1&&
                            <TabPane tab=" 活动" key="5"></TabPane>
                            }
                        {channelIndex==1&&location!='2'&&<TabPane tab=" 优惠券" key="9"></TabPane>}
                        {location!='2'&&<TabPane tab=" 外部链接" key="4"></TabPane>}
                        {location!='2'&&this.props.type!='homeBanner'&&<TabPane tab=" 美房详情" key="7"></TabPane>}
                        {pageProps['10']&&<TabPane tab=" 自助购房" key="10"></TabPane>}
                        {pageProps['11']&&<TabPane tab=" 在线开盘" key="11"></TabPane>}
                        {pageProps['12']&&<TabPane tab=" 小游戏" key="12"></TabPane>}
                        {pageProps['13']&&<TabPane tab=" 直播" key="13"></TabPane>}

                        <TabPane tab="不跳转" key="8"></TabPane>
                    </Tabs>
                    
                    {/*楼盘 1*/}
                    {
                    <div title="楼盘" className={cx(hrefModalObj.hrefType == '1' ? '' : 'hidden')}>
                        <ListPage pageProps={pageProps['1']}/>
                    </div>
                    }
                    
                    {/*秒杀竞拍 2*/}
                    {
                    <div title="秒杀竞拍" className={cx(hrefModalObj.hrefType == '2' ? '' : 'hidden')}>
                        <ListPage pageProps={pageProps['2']}/>
                    </div>
                    }
                    
                    {/*资讯 3*/}
                    {
                    <div title="资讯" className={cx(hrefModalObj.hrefType == '3' ? '' : 'hidden')}>
                        <ListPage pageProps={pageProps['3']}/>
                    </div>
                    }
                     {
                        <div title="优惠券" className={cx(hrefModalObj.hrefType == '9' ? '' : 'hidden')}>
                            <ListPage pageProps={pageProps['9']}/>
                        </div>
                        }
                    {/*外部链接 4*/}
                    {
                    <div className={cx(hrefModalObj.hrefType == '4' ? '' : 'hidden')}>
                        <FormItem {...formItemLayout2} label="跳转链接"
                        extra='请先将外部链接地址邮件发送给集团IT-谭嘉杰(tanjj9@midea.com)，经集团备案转换后再将新地址录入'
                        hasFeedback>
                        {getFieldDecorator('new_href', {
                            initialValue: hrefModalObj.linkUrl || '',
                            // rules: [
                            //   { required: true, whitespace: true, message: `请输入正确链接`, pattern: /(http|ftp|https):\/\/([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?/ },
                            // ],
                        })(<Input
                            placeholder={'请输入链接'}
                            onChange={(e) => {
                            hrefModalObj.outerlinkUrl = e.target.value
                            changeState({hrefModalObj})
                            }}
                        />)}
                        </FormItem>
                    </div>
                    }
                    
                    {/* 活动 5 */}
                    {
                    <div title="活动" className={cx(hrefModalObj.hrefType == '5' ? '' : 'hidden')}>
                        <ListPage pageProps={pageProps['5']}/>
                    </div>
                    }
                    {/* 预约看房 6 */}
                    {
                    <div title="预约看房" className={cx(hrefModalObj.hrefType == '6' ? '' : 'hidden')}>
                        <ListPage pageProps={pageProps['6']}/>
                    </div>
                    }
                      {/* 美房详情 7*/}
                    {
                      this.props.type!='homeBanner'&&  <div title="美房详情" className={cx(hrefModalObj.hrefType == '7' ? '' : 'hidden')}>
                            <ListPage pageProps={pageProps['7']}/>
                        </div>
                     }

                    {/*自助购房 10*/}
                    {
                    <div title="自助购房" className={cx(hrefModalObj.hrefType == '10' ? '' : 'hidden')}>
                        <ListPage pageProps={pageProps['10']}/>
                    </div>
                    }

                    {/*在线开盘 11*/}
                    {
                    <div title="在线开盘" className={cx(hrefModalObj.hrefType == '11' ? '' : 'hidden')}>
                        <ListPage pageProps={pageProps['11']}/>
                    </div>
                    }

                    {/*小游戏 12*/}
                    {
                    <div title="小游戏" className={cx(hrefModalObj.hrefType == '12' ? '' : 'hidden')}>
                        <ListPage pageProps={pageProps['12']}/>
                    </div>
                    }

                    {/*直播 13*/}
                    {
                    <div title="直播" className={cx(hrefModalObj.hrefType == '13' ? '' : 'hidden')}>
                        <ListPage pageProps={pageProps['13']}/>
                    </div>
                    }
                   
                    
                </div>
            </Modal>
        )
    }
        

}